-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Also log any extra data attached to an error #46
Conversation
lib/logger.js
Outdated
pick(['message', 'name', 'stack']) | ||
|
||
const flattenProps = | ||
converge(merge, [ identity, clean ]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😕 I don't follow. Are we picking the props off of an object & then merging them back into the same object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Javascript errors are super weird. The { message, name, stack }
properties are not "own" properties. Instead they are built-in getters. Consequently:
JSON.stringify(new Error('my message')) === '{}'
Which is not at all what we want. In the past we've resolved this with a pick
, which reads the specified props whether they are "own" or not.
With the code in this PR, if we've attached new "own" properties to an error, it will pick
off the special { message, name, stack }
props, and then merge them with the extra "own" props, flattening them into a serializable object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oooh... okay. A comment may be in order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe "own" is the wrong word. I may be thinking of "enumerable". Those three props are not "enumerable", which is why a JSON.stringify
won't pick them up when serializing.
I want to fix this problem in Datadog. But currently we clean errors before logging them, and just log the
{ message, name, stack }
. Any injected trace ids would be scrubbed, and errors would not be attached to the corresponding traces.This PR fixes that, by continuing to log at least the
{ message, name, stack }
for errors, but also any other data that is attached to the error.